package br.ucb.tcc.actions;

import java.sql.SQLException;

import br.ucb.tcc.aiml.AimlCommand;
import br.ucb.tcc.aiml.forms.Set;
import br.ucb.tcc.aiml.forms.Srai;
import br.ucb.tcc.aiml.forms.Think;
import br.ucb.tcc.helper.AimlHelper;
import dao.AlunoDAO;
import dto.AlunoDTO;

public class InitUserInfo extends BotSystemAction<AlunoDTO> {

	@Override
	public String decriptyAction(String action) {
		action = action.replace("initMina: ", "");
		Integer chavePessoa = Integer.parseInt(action); 
		AlunoDTO aluno =  getUserData(chavePessoa);
		return generateXML(aluno);		
	}

	@Override
	String generateXML(AlunoDTO obj) {
		AimlCommand command = new AimlCommand();
		
		Think think = new Think();
		
		Set nome = new Set(obj.getNomePessoa(), "nome");
		Set apelido = new Set(obj.getApelido(), "apelido");
		Set matricula = new Set(obj.getMatricula(), "matricula");
		Set dn = new Set(obj.getDtNascer().toString(),"dn");
		Set sexo = new Set(obj.getSexo(), "sexo");
		Set mail = new Set(obj.getEmail(), "mail");
		
		think.add(nome);
		think.add(apelido);
		think.add(matricula);
		think.add(dn);
		think.add(sexo);
		think.add(mail);
		
		Srai srai = new Srai("testeInitMina");
		
		command.add(think);		
		command.add(srai);
		
		return AimlHelper.magicConversion(command);
	}
	
	private AlunoDTO getUserData(Integer chavePessoa){
		AlunoDAO alunoDAO = new AlunoDAO();
		try {
			return alunoDAO.buscarAluno(chavePessoa);
		} catch (SQLException e) {
			e.printStackTrace();
		}		
		return null;
	}

}
